<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>类里面实现迭代器</title>
</head>
<body>
    <script>
        class Person{
           constructor(name)
           {
              this.name = name;
           }
              friends = ["james","curry","kobe"];
           [Symbol.iterator]()
           {
               let index = 0;
               const iterator = {
                  next:()=>
                  {
                     if(index<this.friends.length)
                     {
                        return {value:this.friends[index++],done:false};
                     }
                     else
                     {
                        return {done:true};
                     }
                  }
               }
               return iterator;
           }
        }

        let p1 = new Person("cq");
        for(name of p1)
        {
            console.log(name);
        }
    </script>
</body>
</html>